<template> 
    <div class="app-container">

                <el-form :inline="true" ref="queryForm" :model="listQuery" size="small" label-width="140px">
                    <el-form-item label="输入搜索：">
                        <el-input style="width: 203px" v-model="listQuery.name" placeholder="名称"></el-input>
                    </el-form-item>
                </el-form>

        <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                      <el-button
                        type="primary"
                        icon="el-icon-plus"
                        size="mini"
                        @click="handleAdd"
                        v-hasPermi="['sys:role:create']"
                      >新增</el-button>
                    </el-col>
                    <el-col :span="1.5">
                      <el-button
                        type="success"
                        icon="el-icon-edit"
                        size="mini"
                        :disabled="single"
                        @click="handleUpdate"
                        v-hasPermi="['sys:role:update']"
                      >修改</el-button>
                    </el-col>
                    <el-col :span="1.5">
                      <el-button
                        type="danger"
                        icon="el-icon-delete"
                        size="mini"
                        :disabled="multiple"
                        @click="handleDelete"
                        v-hasPermi="['sys:role:delete']"
                      >删除</el-button>
                    </el-col>
                    <el-col :span="1.5">
                      <el-button
                        type="warning"
                        icon="el-icon-download"
                        size="mini"
                        @click="handleExport"
                        v-hasPermi="['system:post:export']"
                      >导出</el-button>
                    </el-col>
                  </el-row>
            <el-table ref="giftsCategoryTable"
                      :data="list"
                      style="width: 100%"
                      @selection-change="handleSelectionChange"
                      v-loading="listLoading"
                      border>
                <el-table-column type="selection" width="60" align="center"></el-table-column>

                <el-table-column label="编号" align="center">
                    <template slot-scope="scope">{{scope.row.id}}</template>
                </el-table-column>
                <el-table-column label="标题" align="center">
                    <template slot-scope="scope">{{scope.row.name}}</template>
                </el-table-column>
                <el-table-column label="分类图标" align="center">
                  <template slot-scope="scope"><img style="height: 80px" :src="scope.row.icon"></template>
                </el-table-column>
                <el-table-column label="专题数量" align="center">
                    <template slot-scope="scope">{{scope.row.helpCount}}</template>
                </el-table-column>
                <el-table-column label="状态" align="center">
                  <template slot-scope="scope">
                    <el-switch
                      @change="handleStatusStatusChange(scope.$index, scope.row)"
                      :active-value="1"
                      :inactive-value="0"
                      v-model="scope.row.showStatus">
                    </el-switch>
                  </template>
                </el-table-column>
                <el-table-column label="排序" align="center">
                    <template slot-scope="scope">{{scope.row.sort}}</template>
                </el-table-column>


                <el-table-column label="操作" width="200" align="center">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                @click="handleUpdate(scope.row)">编辑
                        </el-button>
                        <el-button
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

        <div class="pagination-container">

           <pagination
             v-show="total>0"
             :total="total"
             :page.sync="listQuery.pageNum"
             :limit.sync="listQuery.pageSize"
             @pagination="getList"
           />
           </div>
 </div>
</template>
<script>
    import {fetchList, deleteGiftsCategory} from '@/api/pms/GiftsCategory'

    export default {
        name: 'giftsCategoryList',
        data() {
            return {
                operates: [
                    {
                        label: "显示品牌",
                        value: "showGiftsCategory"
                    },
                    {
                        label: "隐藏品牌",
                        value: "hideGiftsCategory"
                    }
                ],
                operateType: null,
                listQuery: {
                    keyword: null,
                    pageNum: 1,
                    pageSize: 10
                },
                list: null,
                   // 非单个禁用
                              single: true,
                              // 非多个禁用
                              multiple: true,
                                // 总条数
                               total: 0,
                               isEdit:false,
                                // 弹出层标题
                                     title: "",
                              // 是否显示弹出层
                                open: false,
                listLoading: true,
                multipleSelection: []
            }
        },
        created() {
            this.getList();
        },
        methods: {
            getList() {
                this.listLoading = true;
                fetchList(this.listQuery).then(response => {
                    this.listLoading = false;
                this.list = response.data.records;
                this.total = response.data.total;
                this.totalPage = response.data.pages;
                this.pageSize = response.data.size;
            });
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleUpdate(index, row) {
                this.$router.push({path: '/pms/updatePmsGiftsCategory', query: {id: row.id}})
            },
            handleDelete(row) {
                 const ids = row.id || this.ids;
        this.$confirm('是否确认要删除该品牌', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteGiftsCategory(row.id).then(response => {
                    this.$message({
                    message: '删除成功',
                    type: 'success',
                    duration: 1000
                });
                this.getList();
            });
            });
            },
            getProductList(index, row) {
                console.log(index, row);
            },
            getProductCommentList(index, row) {
                console.log(index, row);
            },


            handleSizeChange(val) {
                this.listQuery.pageNum = 1;
                this.listQuery.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.listQuery.pageNum = val;
                this.getList();
            },
            searchGiftsCategoryList() {
                this.listQuery.pageNum = 1;
                this.getList();
            },
            handleBatchOperate() {
                console.log(this.multipleSelection);
                if (this.multipleSelection < 1) {
                    this.$message({
                        message: '请选择一条记录',
                        type: 'warning',
                        duration: 1000
                    });
                    return;
                }
                let showStatus = 0;
                if (this.operateType === 'showGiftsCategory') {
                    showStatus = 1;
                } else if (this.operateType === 'hideGiftsCategory') {
                    showStatus = 0;
                } else {
                    this.$message({
                        message: '请选择批量操作类型',
                        type: 'warning',
                        duration: 1000
                    });
                    return;
                }
                let ids = [];
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    ids.push(this.multipleSelection[i].id);
                }
                let data = new URLSearchParams();
                data.append("ids", ids);
                data.append("showStatus", showStatus);
                updateShowStatus(data).then(response => {
                    this.getList();
                this.$message({
                    message: '修改成功',
                    type: 'success',
                    duration: 1000
                });
            });
            },
            addGiftsCategory() {
                this.$router.push({path: '/pms/addPmsGiftsCategory'})
            },
            /** 新增按钮操作 */
                     handleAdd() {
                       this.reset();

                       this.open = true;
                       this.title = "添加角色";
                     },
                     /** 修改按钮操作 */
                     handleUpdate(row) {
                       this.reset();
                       this.isEdit=true;
                       const id = row.id || this.ids

                       getBrand(id).then(response => {
                         this.brand = response.data;
                         this.open = true;
                         this.title = "修改角色";
                       });
                     },
                      /** 导出按钮操作 */
                         handleExport() {
                           const queryParams = this.queryParams;
                           this.$confirm('是否确认导出所有角色数据项?', "警告", {
                               confirmButtonText: "确定",
                               cancelButtonText: "取消",
                               type: "warning"
                             }).then(function() {
                               return exportRole(queryParams);
                             }).then(response => {
                               this.download(response.msg);
                             }).catch(function() {});
                         },
                      // 取消按钮
                         cancel() {
                           this.open = false;
                           this.reset();
                         },
                           // 多选框选中数据
                             handleSelectionChange(selection) {
                               this.ids = selection.map(item => item.id)
                               this.single = selection.length!=1
                               this.multiple = !selection.length
                             },
                         /** 重置按钮操作 */
                             resetQuery() {
                               this.dateRange = [];
                               this.resetForm("queryForm");
                               this.handleQuery();
                             },
                              // 表单重置
                                 reset() {

                                   this.brand = {
                                     id: undefined,
                                     name: undefined,

                                     sort: 0,
                                     status: "0",

                                     description: undefined
                                   };
                                   this.resetForm("form");
                                 },
        }
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>


</style>


